package com.apes.scm.masterdata.area.repository;

import com.apes.framework.jpa.repository.CustomRepository;
import com.apes.scm.masterdata.area.model.Area;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Map;

public interface AreaRepository extends CustomRepository<Area, String> {

    List<Area> findByParentIsNull();

    List<Area> findByParent(String parent);

    @Query(value = "SELECT * FROM  MAS_AREA T WHERE T.NAME LIKE '%'|| :cityName ||'%市' OR T.NAME = :cityName",nativeQuery = true)
    Page<Map> findByCity(@Param("cityName") String cityName, Pageable pageable);

    @Query(value = "SELECT * FROM MAS_AREA T WHERE T.PARENT_ID IS NULL AND T.NAME LIKE '%'|| :provinceName ||'%'",nativeQuery = true)
    Page<Map> findByProvince(@Param("provinceName") String provinceName, Pageable pageable);
}
